class Solution {
    public int maxProfit(int[] prices) {
        if(0 == prices.length || 1 == prices.length) {
            return 0;
        }
        int profit = 0;
        int prev = 0;
        int cur = 1;
        while(cur < prices.length) {
            if(0>=prices[cur] - prices[prev]) {
                prev = cur;
                cur++;
            }else {
                if(profit < prices[cur] - prices[prev]) {
                    profit = prices[cur] - prices[prev];
                }
                cur++;
            }
        }
        return profit;
    }
}